package com.api.shopapi.mapper;


import com.api.shopapi.entity.ActivityItem;
import com.api.shopapi.entity.ActivityOrder;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface ActivityOrderMapper {


    @Insert("insert into activity_order " +
            "(" +
            "ActivityOrderCode," +
            "PracticeSiteCode," +
            "CommandCenterCode," +
            "GovernmentCode," +
            "ActivityContentCode," +
            "Status," +
            "CreateTime" +
            ") " +
            "values " +
            "(" +
            "#{activityOrder.ActivityOrderCode}," +
            "#{activityOrder.PracticeSiteCode}," +
            "#{activityOrder.CommandCenterCode}," +
            "#{activityOrder.GovernmentCode}," +
            "#{activityOrder.ActivityContentCode}," +
            "#{activityOrder.Status}," +
            "#{activityOrder.CreateTime}" +
            ")" )
    int insert(@Param("activityOrder") ActivityOrder activityOrder);


    @Delete("delete from activity_order where activityOrderCode=#{activityOrderCode}")
    int delete(@Param("activityOrderCode") String activityOrderCode);


    @Update("update activity_order set " +
            " Status=#{activityOrder.Status}," +
            " PassTime=#{activityOrder.PassTime}," +
            " VolunteerTeamCode=#{activityOrder.VolunteerTeamCode}," +
            " ReceiveTime=#{activityOrder.ReceiveTime}," +
            " ActivityStartTime=#{activityOrder.ActivityStartTime}," +
            " ActivityEndTime=#{activityOrder.ActivityEndTime}," +
            " Evaluate=#{activityOrder.Evaluate}," +
            " EvaluateTime=#{activityOrder.EvaluateTime}," +
            " ActivityAddress=#{activityOrder.ActivityAddress}" +
            " where activityOrderCode=#{activityOrder.activityOrderCode}")
    int update(@Param("activityOrder") ActivityOrder activityOrder);


    @Select("select * from activity_order where activityOrderCode=#{activityOrderCode} limit 1")
    ActivityOrder getByActivityOrderCode(@Param("activityOrderCode") String activityOrderCode);




    /**
     * 指挥中心点单列表
     * */
    @Select("<script>" +
            "select * from activity_order where governmentCode=#{governmentCode} and Status = #{status} " +
            "<if test =' commandCenterCode != \"\" '>" +
            " and commandCenterCode = #{commandCenterCode} " +
            "</if>" +
            " order by CreateTime desc" +
            "</script>")
    List<ActivityOrder> ListByCommandCenterCode(@Param("governmentCode") String governmentCode,
                                                @Param("commandCenterCode") String commandCenterCode,@Param("status") int status);


    /**
     * 实践站点点单列表
     * */
    @Select("<script>" +
            "select * from activity_order where practiceSiteCode=#{practiceSiteCode} and Status = #{status} " +
            " order by CreateTime desc" +
            "</script>")
    List<ActivityOrder> ListByPracticeSiteCode(@Param("practiceSiteCode") String practiceSiteCode,@Param("status") int status);

    /**
     * 志愿队伍点单列表
     * */
    @Select("<script>" +
            "select * from activity_order where volunteerTeamCode=#{volunteerTeamCode} and Status = #{status} " +
            " order by CreateTime desc" +
            "</script>")
    List<ActivityOrder> ListByVolunteerTeamCode(@Param("volunteerTeamCode") String volunteerTeamCode,@Param("status") int status);


}
